package com.blrs.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.blrs.domain.MemberTemplate;
import com.blrs.service.member.IMemberTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.blrs.common.core.controller.BaseController;
import com.blrs.common.core.domain.AjaxResult;

import com.blrs.common.utils.poi.ExcelUtil;
import com.blrs.common.core.page.TableDataInfo;


@RestController
@RequestMapping("/member/template")
public class MemberTemplateController extends BaseController {
    @Autowired
    private IMemberTemplateService memberTemplateService;


    @GetMapping("/list")
    public TableDataInfo list(MemberTemplate memberTemplate) {
        startPage();
        List<MemberTemplate> list = memberTemplateService.selectMemberTemplateList(memberTemplate);
        return getDataTable(list);
    }

    @PostMapping("/export")
    public void export(HttpServletResponse response, MemberTemplate memberTemplate) {
        List<MemberTemplate> list = memberTemplateService.selectMemberTemplateList(memberTemplate);
        ExcelUtil<MemberTemplate> util = new ExcelUtil<MemberTemplate>(MemberTemplate.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }


    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(memberTemplateService.selectMemberTemplateById(id));
    }


    @PostMapping
    public AjaxResult add(@RequestBody MemberTemplate memberTemplate) {
        return toAjax(memberTemplateService.insertMemberTemplate(memberTemplate));
    }


    @PutMapping
    public AjaxResult edit(@RequestBody MemberTemplate memberTemplate) {
        return toAjax(memberTemplateService.updateMemberTemplate(memberTemplate));
    }


    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(memberTemplateService.deleteMemberTemplateByIds(ids));
    }

    @GetMapping("/qualificationTree")
    public AjaxResult treeHonor() {
        return memberTemplateService.selectQualificationByType();
    }

    /**
     * 批量新增成员模板
     */
    @PostMapping("/batchAdd")
    public AjaxResult batchAdd(@RequestParam("typeId") String typeId,
                               @RequestBody List<Map<String, Object>> memberList) {
        return memberTemplateService.batchInsertMemberTemplate(typeId, memberList);
    }
}
